package com.example.diagnodroid.memoire;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.os.Bundle;
import android.os.StatFs;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.diagnodroid.R;

@SuppressLint("NewApi")
public class SystemMemoryActivity extends Activity {
	
	ProgressBar memoryBar;
	TextView infoMemoryText;
	
    StatFs stat;
    
    double memoryMax;
    double memoryAvailable;
    double memoryUsed;
    
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.system_memory_layout);

		memoryBar = (ProgressBar) findViewById(R.id.memory_bar_system);
		infoMemoryText = (TextView) findViewById(R.id.info_system_memory);
        
		MemoryInfo memoryInfo = new MemoryInfo();
		ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
		activityManager.getMemoryInfo(memoryInfo);
		 
		memoryAvailable= memoryInfo.availMem / 1048576;
		memoryMax= memoryInfo.totalMem / 1048576;
		memoryUsed = memoryMax-memoryAvailable;
		
                                
		infoMemoryText.append("\n mémoire totale : " + memoryMax + " MB\n" 
		+ "\n mémoire utilisée : " + memoryUsed + " MB\n" 
				+ "\n mémoire disponible : " + memoryAvailable + " MB\n");
		
		int percent_used = 	((int)memoryUsed * 100)/(int)memoryMax;
				
		memoryBar.setMax(100);
		memoryBar.setProgress(percent_used);
	}
		
	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}	

}